//
//  ViewController.swift
//  UIViewDemo
//
//  Created by 劢克科技 on 2019/3/7.
//  Copyright © 2019 劢克科技. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    lazy var btn = UIButton(type: .system)
    let popAnimate = PopAnimateDelegate()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setUI()
    }

    func setUI() {
        view.backgroundColor = UIColor.white
        view.addSubview(btn)
        btn.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
        btn.setTitle("Present Controller", for: .normal)
        btn.translatesAutoresizingMaskIntoConstraints = false
        btn.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        btn.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
    }
    
    @objc func buttonClick() {
        let controller = DemoViewController()
        // 使用自定义动画
        // 1.将modalPresentationStyle属性设置为.custom
        // 2.将transitioningDelegate设置为自定义的动画文件即可。
        controller.modalPresentationStyle = .custom
        controller.transitioningDelegate = popAnimate
        present(controller, animated: true, completion: nil)
    }
    
}
